//
// Description: 5964. 执行所有后缀指令
// Created by Loading on 2021/12/26.
//

#include <bits/stdc++.h>

using namespace std;

vector<int> executeInstructions(int n, vector<int> &startPos, string s) {
    int m = s.size();
    vector<int> res(m);
    for (int i = 0; i < m; ++i) {
        int x = startPos[0];
        int y = startPos[1];
        int cnt = 0;
        for (int j = i; j < m; ++j) {
            if (s[j] == 'L') {
                --y;
            } else if (s[j] == 'R') {
                ++y;
            } else if (s[j] == 'U') {
                --x;
            } else {
                ++x;
            }
            if (x < 0 || y < 0 || x >= n || y >= n) {
                break;
            }
            ++cnt;
        }
        res[i] = cnt;
    }

    return res;
}

int main() {
    int n = 3;
    vector<int> startPos = {0, 1};
    string s = "RRDDLU";
    vector<int> res = executeInstructions(n, startPos, s);
    for (auto x : res) {
        cout << x << ' ';
    }
    cout << endl;

    return 0;
}